// ES6
import router from '@system.router';
import tools from '../../common/utils/tools.js';

export default {
  data: {
    title: 'hello world',
    fruits: [
      '🍌',
      '🍇',
      '🌰',
      '🥝',
      'apple'
    ],
    list: [
      'aaa',
      'bbb'
    ],
    isShow: true,
    num: 100,
    obj: {
      x: 'xxx',
      y: 'yyy'
    }
  },

  computed: {
    doubleNum() {
      return this.num * 2
    }
  },

  // 事件响应函数
  handleButtonClick(title) {
//    console.log(JSON.stringify(title))
    this.isShow = !this.isShow
    this.title = title
//    console.log(0)
    router.push({
      uri: 'pages/details/details'
    })
  },

  handleAddClick() {
    const that = this
    setTimeout(function() {
      that.num += 90
    }, 2000)
  },

  handleChangeClick() {
    this.obj.x = 'xxxxxx'
//    this.obj.z = 'zzz'
    this.$set('obj.z', 'zzz')
    this.$delete('obj')
    console.log(this.obj)
  },

  onReady() {
//    console.log(JSON.stringify(this.$app.$def))
    console.log(this.$app.$def.x)
    this.$app.$def.foo()

    const num = tools.add(30, 40)
    console.log(num)

    const num2 = this.$app.$def.minus(100, 30)
    console.log(num2)
    console.log(this.$app.$def.x)


    this.$watch('num', function(newValue, oldValue) {
      console.log(newValue)
      console.log(oldValue)
    })
  }
}